<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页开关灯</title>
    <style>
        div{
            /* margin: 50px auto; */
            width: 100%;
            height: 500px;
            background-color: white;
            border: 1px solid black;
        }
        div input{
            width: 100px;
            height: 50px;
        }
    </style>
</head>
<body>
    <div class="change">
        <input type="submit" id="click" value='关灯'>
    </div>

    <script>
        //1.找到元素对象
        var input=document.querySelector('#click');
        var div=document.querySelector('.change');
        var flag=1;//白色，关灯
        //2.绑定事件处理程序
        //单击开关灯，改变页面背景颜色、文字
        input.onclick=function(){
            if(flag==1){
                div.style.backgroundColor='black';
                this.value='开灯';
                flag=0;
            }else{
                div.style.backgroundColor='white';
                this.value='关灯';
                flag=1;
            }          
        }
    </script>
</body>
</html>